package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * C端购物车数据访问层接口
 *
 * @Author Vsunks.v
 * @Date 2023/5/7 15:11
 * @Blog blog.sunxiaowei.net
 * @Description:
 */
public interface ShoppingCartMapper {
    /**
     * 查询动态条件查询当前登录用户的购物车
     *
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 购物车项数量加一
     *
     * @param scIdb
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    int updateNumberById(ShoppingCart scIdb);

    /**
     * 新增一条数据
     *
     * @param shoppingCart 数据
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    int insert(ShoppingCart shoppingCart);

    /**
     * 根据用户id，删除所有所属购物车项
     *
     * @param userId 用户id
     * @return 影响的行数
     */
    @Delete("delete from shopping_cart where user_id =#{userId};")
    int deleteByUserId(@Param("userId") Long userId);

    /**
     * 根据条件删除购物车项
     * @param shoppingCart
     */
    void deleteByCondition(ShoppingCart shoppingCart);

    /**
     * 批量添加到购物车
     * @param shoppingCarts
     * @return 影响的行数
     */
    int insertBatch( List<ShoppingCart> shoppingCarts);

}
